{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Project"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For this project you have 4 files containing information about persons.\n",
    "\n",
    "The files are:\n",
    "* `personal_info.csv` -   personal information such as name, gender, etc. (one row per person)\n",
    "* `vehicles.csv` -   what vehicle people own (one row per person)\n",
    "* `employment.csv` -   where a person is employed (one row per person)\n",
    "* `update_status.csv` -   when the person's data was created and last updated\n",
    "\n",
    "Each file contains a key, `SSN`, which **uniquely** identifies a person.\n",
    "\n",
    "This key is present in **all** four files.\n",
    "\n",
    "You are guaranteed that the same SSN value is present in **every** file, and that it only appears **once per file**.\n",
    "\n",
    "In addition, the files are all sorted by SSN, i.e. the SSN values appear in the same order in each file."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Goal 1\n",
    "\n",
    "Your first task is to create iterators for each of the four files that contained cleaned up data, of the correct type (e.g. string, int, date, etc), and represented by a named tuple.\n",
    "\n",
    "For now these four iterators are just separate, independent iterators."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Goal 2\n",
    "\n",
    "Create a single iterable that combines all the columns from all the iterators.\n",
    "\n",
    "The iterable should yield named tuples containing all the columns.\n",
    "\n",
    "Normally you should ensure that the SSN's match across all the files (i.e. identical row numbers in each file refer to the same SSN). However, in this case you do not need to do so as the data is already \"aligned\" - all the files are guaranteed to be in SSN sort order, every SSN is unique, and every SSN appears in every file.\n",
    "\n",
    "Just make sure that in your iterable the SSN is not repeated 4 times - one time per row is enough!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Goal 3\n",
    "\n",
    "Next, you want to identify any stale records, where stale simply means the record has not been updated since 3/1/2017 (e.g. last update date < 3/1/2017). Create an iterator that only contains current records (i.e. not stale) based on the `last_updated` field from the `status_update` file."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Goal 4\n",
    "\n",
    "Find the largest group of car makes for each gender.\n",
    "\n",
    "Possibly more than one such group per gender exists (equal sizes)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "#### Hints"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You will not be able to use a simple split approach here, as I explain in the video.\n",
    "\n",
    "Instead you should use the `csv` module and the `reader` function.\n",
    "\n",
    "Here's a simple example of how to use it - you will need to expand on this for your project goals, but this is a good starting point."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import csv\n",
    "\n",
    "def read_file(file_name):\n",
    "    with open(file_name) as f:\n",
    "        rows = csv.reader(f, delimiter=',', quotechar='\"')\n",
    "        yield from rows\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['ssn', 'first_name', 'last_name', 'gender', 'language']\n",
      "['100-53-9824', 'Sebastiano', 'Tester', 'Male', 'Icelandic']\n",
      "['101-71-4702', 'Cayla', 'MacDonagh', 'Female', 'Lao']\n",
      "['101-84-0356', 'Nomi', 'Lipprose', 'Female', 'Yiddish']\n",
      "['104-22-0928', 'Justinian', 'Kunzelmann', 'Male', 'Dhivehi']\n"
     ]
    }
   ],
   "source": [
    "from itertools import islice\n",
    "\n",
    "rows = read_file('personal_info.csv')\n",
    "for row in islice(rows, 5):\n",
    "    print(row)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As you can see, the data is already separated into a list containing the individual fields - but of course they are all just strings."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Good luck!"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
